package com.example.auth.filter;

import com.example.auth.utils.ResponseUtil;
import com.example.auth.utils.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: LiYang
 * @create: 2023-07-28 10:42
 * @Description:
 * @Version 1.0
 **/
@Component
public class AccessDenied implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        // 通过 response 写入返回内容
        ResponseUtil.out(response, Result.fail("权限不足"));
    }
}
